﻿using System.IO;
using System.Net;

namespace ServerCrafter.ClassLibrary.Tools
{
    internal class WebClient
    {
        /// <summary>
        /// Downloads the the website at the specified URL as a string.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <returns></returns>
        public static string DownloadString(string url)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.UserAgent = "ServerCrafter";
            httpWebRequest.ReadWriteTimeout = 5000;
            httpWebRequest.Timeout = 5000;

            var cookieContainer = new CookieContainer();
            httpWebRequest.CookieContainer = cookieContainer;

            return new StreamReader(httpWebRequest.GetResponse().GetResponseStream()).ReadToEnd();
        }
    }
}